home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5233 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.7 KB  |  85 lines

  1. Path: news.ust.hk!eg_spm
  2. From: eg_spm@uxmail.ust.hk (She Pei Man James)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: RETURN ();
  5. Date: 9 Feb 1996 02:43:12 GMT
  6. Organization: The Hong Kong University of Science and Technology
  7. Message-ID: <4fecc0$5os@news.ust.hk>
  8. References: <DMFxxq.7M7@emi.net>
  9. NNTP-Posting-Host: ustsu26.ust.hk
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. samstar@emi.net wrote:
  13. : Is there a way to return muliple values to main from a seperate function ?
  14.  
  15. : ex :
  16.  
  17. : int main(void)
  18. : {
  19. :   Input_data();
  20. :   printf("Here all the input data");
  21. :   
  22. :   return 0;
  23. : }
  24.  
  25. : int Input_data()
  26. : {
  27. :   x=5,y=30,z=10    /* These were gotten by asking questions */
  28. :             /* using printf / scanf/fgets (what ever)  */
  29. :             /*point is they are gotten by question      */
  30.  
  31. : return(x,y,z);
  32. : }
  33.  
  34. : how will main be able to see these values ?
  35.  
  36. : I tried this in main didn't help :
  37.  
  38. : int main(x,y,z)
  39. : {
  40. : ect...
  41. : }
  42.  
  43. : if anyone can help... please email me at samstar@emi.net
  44.  
  45.  
  46. :                         thanks....
  47.  
  48. :                         samstar
  49. ya...i think it's better to manipulate this case by the command "struct"
  50. e.g. struct numbers {           /* This is a delcaration of structure...
  51.      int x;                        and "numbers" a the structure name defined
  52.      int y;                        by u...and x,y,z is the elements in this
  53.      int z;                        structure */
  54.      }
  55.      
  56.      void  main() {             /* declare main with the type of "numbers"
  57.      
  58.      numbers XYZ;                   declare a variable XYZ in this type also.
  59.      
  60.      Input_data(XYZ);               Using function Input_data to assign value
  61.                                     to x, y, z.
  62.      printf(XYZ.x,XYZ.y,
  63.             XYZ.z)                  diaplay values of x,y,z
  64.  
  65.      numbers Input_data(numbers XYZ) {    /* declare the return type as 
  66.      XYZ.x=1;                              "numbers" also and the input
  67.      XYZ.y=2;                   parameter as "numbers" type
  68.      XYZ.z=3;                             /* assign values to specified
  69.      return XYZ;                             elements and then return them
  70.      }                                       through a struct. (numbers)
  71. }
  72. as i am using C++ in usual so may be there are some syntax error
  73. however i can sure that the function of structure in C and C++ are the 
  74. same and this alroigthm would be work!
  75. for more detail ...u may try to refer some book of structure this command!
  76. hope this help!
  77.                                 James
  78.  
  79.  --
  80. ======= The Hong Kong University of Science and Technology =======
  81.                     --- Computer Engineering ---
  82. [│\ÑAñσ] PeiMan.                                           eg_spm@stu.ust.hk
  83. Pager: 71714141                                         csjames@ug.cs.ust.hk
  84. http://susis.ust.hk/~spmjames                          spmjames@susis.ust.hk
  85.